package com.asiainfo.dacp.datastash.orm.po.inter;

import com.asiainfo.dacp.datastash.orm.po.inter.pk.DataStashUnitInterPoPK;
import com.asiainfo.dacp.jpa.annotation.ColumnPosition;
import com.asiainfo.dacp.util.DateHelper;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name="dacp_datastash_inter")
@NoArgsConstructor
public class DataStashUnitInterPo {

    @EmbeddedId
    private DataStashUnitInterPoPK dataStashUnitInterPoPK;

    @Column(name="unit_code",length = 100)
    @ColumnPosition(2)
    private String unitCode;

    @Column(name="create_dt")
    @ColumnPosition(3)
    private Date createDt=new Date();

    @Transient
    private String createDate;

    public String getCreateDate(){
        if(createDate==null || createDate.length()==0){
            createDate = DateHelper.formatDateTime(createDt);
        }
        return createDate;
    }

    public void setCreateDate(String createDate){
        this.createDate = createDate;
        createDt = DateHelper.parseDateTime(createDate);
    }

    public DataStashUnitInterPo(DataStashUnitInterPoPK dataStashUnitInterPoPK, String unitCode) {
        this.dataStashUnitInterPoPK = dataStashUnitInterPoPK;
        this.unitCode = unitCode;
    }
}
